<template>
    <div class="render-function-page">
        <heading>TV Finder</heading>
        <RenderMenu>
            <h4>Hi From Default slot</h4>

            <template #namedSlot>
                <h3>Hello From Named Slot</h3>
            </template>

            <template #sc="{ shows }">
                <h3 v-if="shows?.length > 0">
                    Average Score {{ computedAverage(shows).toFixed(2) }}
                </h3>
            </template>
        </RenderMenu>

        <footer>
            Fork From <span>❤️</span>
            <a
                class="rainbow-link"
                href="https://github.com/ErikCH/RenderFunctionsVue3"
                >RenderFunctionsVue3</a
            >❤️
        </footer>
    </div>
</template>

<script setup lang="ts">
import Heading from "./Heading.vue";
import RenderMenu from "./RenderMenu.vue";

const computedAverage = (shows: []) =>
    shows.reduce((acc, info: any) => +info?.score + acc, 0) / shows.length;
</script>

<style scoped lang="scss">
.render-function-page {
    font-family: Avenir, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-align: center;
    color: #2c3e50;
    margin-top: 60px;
}

footer {
    position: fixed;
    bottom: 24px;
    left: 50%;
    color: $theme-color;
    text-align: center;
    transform: translateX(-50%);
}
</style>
